<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    div {
      width: 80px;
    }

    input[type=text] {
      width: 50px;
      height: 44px;
      outline: none;
      border: 1px solid #ccc;
      text-align: center;
      border-right: 0;
    }

    input[type=button] {
      height: 24px;
      width: 22px;
      cursor: pointer;
    }

    input {
      float: left;
      border: 1px solid #ccc;

    }
  </style>
</head>

<body>
  <div>
    <input type="text" id="total" value="1" readonly>
    <input type="button" value="+" id="add">
    <input type="button" value="-" id="reduce" disabled>
    <script>
      // 1. 获取需要使用到的所有元素
      let txt = document.querySelector('#total')
      let add = document.querySelector('#add')
      let reduce = document.querySelector('#reduce')

      // 2. 给 + 按钮添加点击事件，将数字递增
      add.addEventListener('click',function(){
        txt.value = txt.value - 0 + 1
        // 当用户点击 + 按钮之后，数字发生了变化，要对 - 按钮复位
        if(txt.value != '1'){
          reduce.disabled = false
        }
      })

      // 3. 给 - 按钮添加点击事件，将数字递减
      reduce.addEventListener('click',function(){
        txt.value = txt.value - 1
        // 4. 当数字递减到1的时候，禁用 - 按钮
        if(txt.value === '1'){
          reduce.disabled = true
        }
      })
      

      
    </script>
  </div>
</body>

</html>